#ifndef __LOGGER_H__
#define __LOGGER_H__

#include <stdint.h>
#include <stdio.h>

#define LOG_BUF_SIZE			256
#define LOG_HEX_WIDTH           32

/* Debug level */
#define LOG_LEVEL_FATAL         0
#define LOG_LEVEL_ERROR         1
#define LOG_LEVEL_WARN          2
#define LOG_LEVEL_INFO          3
#define LOG_LEVEL_DEBUG         4
#define LOG_LEVEL_VERBOSE       5

#ifndef LOG_LEVEL
#define LOG_LEVEL	LOG_LEVEL_INFO
#endif

#ifndef LOG_TAG
#define LOG_TAG		"unknown"
#endif

#if LOG_LEVEL >= LOG_LEVEL_VERBOSE
#define LOG_V(fmt, ...) logger_output(LOG_LEVEL_VERBOSE, LOG_TAG, __LINE__, fmt, ##__VA_ARGS__)
#else
#define LOG_V(fmt, ...)
#endif

#if LOG_LEVEL >= LOG_LEVEL_DEBUG
#define LOG_D(fmt, ...) logger_output(LOG_LEVEL_DEBUG, LOG_TAG, __LINE__, fmt, ##__VA_ARGS__)
#else
#define LOG_D(fmt, ...)
#endif

#if LOG_LEVEL >= LOG_LEVEL_INFO
#define LOG_I(fmt, ...) logger_output(LOG_LEVEL_INFO, LOG_TAG, __LINE__, fmt, ##__VA_ARGS__)
#else
#define LOG_I(fmt, ...)
#endif

#if LOG_LEVEL >= LOG_LEVEL_WARN
#define LOG_W(fmt, ...) logger_output(LOG_LEVEL_WARN, LOG_TAG, __LINE__, fmt, ##__VA_ARGS__)
#else
#define LOG_W(fmt, ...)
#endif

#if LOG_LEVEL >= LOG_LEVEL_ERROR
#define LOG_E(fmt, ...) logger_output(LOG_LEVEL_ERROR, LOG_TAG, __LINE__, fmt, ##__VA_ARGS__)
#else
#define LOG_E(fmt, ...)
#endif

#if LOG_LEVEL >= LOG_LEVEL_FATAL
#define LOG_F(fmt, ...) logger_output(LOG_LEVEL_FATAL, LOG_TAG, __LINE__, fmt, ##__VA_ARGS__)
#else
#define LOG_F(fmt, ...)
#endif


void logger_output(int level, const char *tag, int line_num, const char *fmt, ...);

#if LOG_LEVEL >= LOG_LEVEL_VERBOSE
#define LOG_HEX_V(array, size, fmt, ...) 	\
{											\
    LOG_V(fmt, ##__VA_ARGS__);				\
    logger_array(array, size);				\
}
#else
#define LOG_HEX_V(array, size, fmt, ...)
#endif

#if LOG_LEVEL >= LOG_LEVEL_ERROR
#define LOG_HEX_E(array, size, fmt, ...) 	\
{											\
    LOG_E(fmt, ##__VA_ARGS__);				\
    logger_array(array, size);				\
}
#else
#define LOG_HEX_E(array, size, fmt, ...)
#endif

void logger_array(const void *buf, int size);


#endif /* DEBUG_LOG */
